package com.rc.entity.web;

import com.rc.util.HttpCode;

import java.util.List;

public class Result<T> {
    //返回码
    private int code;
    //返回信息
    private String message;
    //返回数据
    private T data;

    public static <T> Result<T> SUCCESS(HttpCode httpCode,T data){
        Result<T> result = new Result<>();
        result.code = httpCode.getCode();
        result.message = httpCode.getMsg();
        result.data = data;
        return result;
    }

    public static <T> Result<T> SUCCESS(HttpCode httpCode){
        Result<T> result = new Result<>();
        result.code = httpCode.getCode();
        result.message = httpCode.getMsg();
        return result;
    }

    public static <T> Result<T> SUCCESS(){
        return SUCCESS(HttpCode.SUCCESS);
    }

    public static  <T> Result<T> SUCCESS(String message){
        Result<T> result = new Result<>();
        result.code = HttpCode.SUCCESS.getCode();
        result.message = message;
        return result;
    }

    public static  <T> Result<T> SUCCESS(T data){
        Result<T> result = new Result<>();
        result.code = HttpCode.SUCCESS.getCode();
        result.message = HttpCode.SUCCESS.getMsg();
        result.data = data;
        return result;
    }

    public static <T> Result<T> ERROR(HttpCode httpCode,T data){
        Result<T> result = new Result<>();
        result.code = httpCode.getCode();
        result.message = httpCode.getMsg();
        result.data = data;
        return result;
    }

    public static <T> Result<T> ERROR(T data){
        Result<T> result = new Result<>();
        result.code = HttpCode.SERVICE_ERROR.getCode();
        result.message = HttpCode.SERVICE_ERROR.getMsg();
        result.data = data;
        return result;
    }

    public static <T> Result<T> ERROR(HttpCode httpCode){
        Result<T> result = new Result<>();
        result.code = httpCode.getCode();
        result.message = httpCode.getMsg();
        return result;
    }

    public static <T> Result<T> ERROR(String message){
        Result<T> result = new Result<>();
        result.code = HttpCode.SERVICE_ERROR.getCode();
        result.message = message;
        return result;
    }

    public static <T> Result<T> ERROR(){
        return ERROR(HttpCode.SERVICE_ERROR);
    }

    public static <T> Result<T> ERROR(int code, String message) {
        Result<T> result = new Result<>();
        result.code = code;
        result.message = message;
        return result;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
